import {RENAME_TITLE,} from "../../../constants/ActionTypes";

function channelReducer(channel, action) {
  switch (action.type) {
    case RENAME_TITLE : {
      return {
        ...channel,
        favorite: channel.favorite === 1 ? 0 : 1,
      }
    }
    default:
      return channel
  }
}

export default function reducer(state = {}, action) {
  switch (action.type) {

    case RENAME_TITLE: {
      const channel = state[action.id]
      if (channel) {
        return {
          ...state,
          [action.id]: channelReducer(channel, action),
        }
      }
      return state
    }
    default:
      return state
  }
}
